function [IncAdvExpChallDem_Weighted_Polarization, IncAdvExpChallRep_Weighted_Polarization, IncAdvInExpChallDem_Weighted_Polarization, IncAdvInExpChallRep_Weighted_Polarization,  ExpChalltoIncDem_Weighted_Polarization, ExpChalltoIncRep_Weighted_Polarization, InExpChalltoIncDem_Weighted_Polarization, InExpChalltoIncRep_Weighted_Polarization] = getPolarization(Theta, VoteDem, VoterIdeal, CandTypeDem, CandTypeRep, DemCandIdeal, DemPartyIdeal, RepCandIdeal, RepPartyIdeal, RHSControls, UtilFuncParam, ChoiceProbForm, Dist_Index, Polarization_Factor)

Lambdas = Theta(1:3,:);
Betas = Theta(4:6,:);
Gamma = Theta(length(Theta),:);



if length(RHSControls(1,:)) >= 1
    RHSCoeff = Theta(7:6+length(RHSControls(1,:)),:);
    SingleIndexVal = CandTypeDem(:,1:3)*Betas(1:3,:) - CandTypeRep(:,1:3)*Betas(1:3,:) + RHSControls*RHSCoeff;
else
    SingleIndexVal = CandTypeDem(:,1:3)*Betas(1:3,:) - CandTypeRep(:,1:3)*Betas(1:3,:);
end


if length(RHSControls(1,:)) >= 1
    RHSCoeff = Theta(7:6+length(RHSControls(1,:)),:);

    SingleIndexValCounterFacIncDem = Betas(1,:) - CandTypeRep(:,1:3)*Betas(1:3,:) + RHSControls*RHSCoeff;
    SingleIndexValCounterFacIncRep = CandTypeDem(:,1:3)*Betas(1:3,:) - Betas(1,:) + RHSControls*RHSCoeff;
    
    SingleIndexValCounterFacExpChallDem = Betas(2,:) - CandTypeRep(:,1:3)*Betas(1:3,:) + RHSControls*RHSCoeff;
    SingleIndexValCounterFacExpChallRep = CandTypeDem(:,1:3)*Betas(1:3,:) - Betas(2,:) + RHSControls*RHSCoeff;
    
    SingleIndexValCounterFacInExpChallDem = Betas(3,:) - CandTypeRep(:,1:3)*Betas(1:3,:) + RHSControls*RHSCoeff;
    SingleIndexValCounterFacInExpChallRep = CandTypeDem(:,1:3)*Betas(1:3,:) - Betas(3,:) + RHSControls*RHSCoeff;

    
else
    
    SingleIndexValCounterFacIncDem = Betas(1,:) - CandTypeRep(:,1:3)*Betas(1:3,:);
    SingleIndexValCounterFacIncRep = CandTypeDem(:,1:3)*Betas(1:3,:) - Betas(1,:);

    
    SingleIndexValCounterFacExpChallDem = Betas(2,:) - CandTypeRep(:,1:3)*Betas(1:3,:);
    SingleIndexValCounterFacExpChallRep = CandTypeDem(:,1:3)*Betas(1:3,:) - Betas(2,:);
  
    SingleIndexValCounterFacInExpChallDem = Betas(3,:) - CandTypeRep(:,1:3)*Betas(1:3,:);
    SingleIndexValCounterFacInExpChallRep = CandTypeDem(:,1:3)*Betas(1:3,:) - Betas(3,:);    
    
end


EstPosDem=(repmat(DemCandIdeal, 1, 3).*CandTypeDem)*(1-Lambdas) + (repmat(DemPartyIdeal, 1, 3).*CandTypeDem)*(Lambdas);
EstPosRep=(repmat(RepCandIdeal, 1, 3).*CandTypeRep)*(1-Lambdas) + (repmat(RepPartyIdeal, 1, 3).*CandTypeRep)*(Lambdas);
SingleIndexPolicy = -Gamma.*abs(EstPosDem-VoterIdeal).^UtilFuncParam+Gamma.*abs(EstPosRep-VoterIdeal).^UtilFuncParam;

SingleIndex = SingleIndexPolicy + SingleIndexVal;

EstPosDem_Polarization=(repmat(DemCandIdeal, 1, 3).*CandTypeDem)*(1-Lambdas) + (repmat(Polarization_Factor*DemPartyIdeal, 1, 3).*CandTypeDem)*(Lambdas);
EstPosRep_Polarization=(repmat(RepCandIdeal, 1, 3).*CandTypeRep)*(1-Lambdas) + (repmat(Polarization_Factor*RepPartyIdeal, 1, 3).*CandTypeRep)*(Lambdas);


SingleIndexPolicy_Polarization = -Gamma.*abs(EstPosDem_Polarization-VoterIdeal).^UtilFuncParam+Gamma.*abs(EstPosRep_Polarization-VoterIdeal).^UtilFuncParam;
SingleIndex_Polarization = SingleIndexPolicy_Polarization + SingleIndexVal;

EstPosDemCounterFacInc = DemCandIdeal*(1-Lambdas(1,:))+DemPartyIdeal*(Lambdas(1,:));
EstPosRepCounterFacInc = RepCandIdeal*(1-Lambdas(1,:))+RepPartyIdeal*(Lambdas(1,:));

EstPosDemCounterFacExpChall = DemCandIdeal*(1-Lambdas(2,:))+DemPartyIdeal*(Lambdas(2,:));
EstPosRepCounterFacExpChall = RepCandIdeal*(1-Lambdas(2,:))+RepPartyIdeal*(Lambdas(2,:));

EstPosDemCounterFacInExpChall = DemCandIdeal*(1-Lambdas(3,:))+DemPartyIdeal*(Lambdas(3,:));
EstPosRepCounterFacInExpChall = RepCandIdeal*(1-Lambdas(3,:))+RepPartyIdeal*(Lambdas(3,:));

EstPosDemCounterFacInc_Polarization = DemCandIdeal*(1-Lambdas(1,:))+Polarization_Factor*DemPartyIdeal*(Lambdas(1,:));
EstPosRepCounterFacInc_Polarization = RepCandIdeal*(1-Lambdas(1,:))+Polarization_Factor*RepPartyIdeal*(Lambdas(1,:));

EstPosDemCounterFacExpChall_Polarization = DemCandIdeal*(1-Lambdas(2,:))+Polarization_Factor*DemPartyIdeal*(Lambdas(2,:));
EstPosRepCounterFacExpChall_Polarization = RepCandIdeal*(1-Lambdas(2,:))+Polarization_Factor*RepPartyIdeal*(Lambdas(2,:));

EstPosDemCounterFacInExpChall_Polarization = DemCandIdeal*(1-Lambdas(3,:))+Polarization_Factor*DemPartyIdeal*(Lambdas(3,:));
EstPosRepCounterFacInExpChall_Polarization = RepCandIdeal*(1-Lambdas(3,:))+Polarization_Factor*RepPartyIdeal*(Lambdas(3,:));


SingleIndexPolicyCounterFacDemInc = -Gamma.*abs(EstPosDemCounterFacInc-VoterIdeal).^UtilFuncParam+Gamma.*abs(EstPosRep-VoterIdeal).^UtilFuncParam;
SingleIndexPolicyCounterFacRepInc = -Gamma.*abs(EstPosDem-VoterIdeal).^UtilFuncParam+Gamma.*abs(EstPosRepCounterFacInc-VoterIdeal).^UtilFuncParam;

SingleIndexPolicyCounterFacDemExpChall = -Gamma.*abs(EstPosDemCounterFacExpChall-VoterIdeal).^UtilFuncParam+Gamma.*abs(EstPosRep-VoterIdeal).^UtilFuncParam;
SingleIndexPolicyCounterFacRepExpChall = -Gamma.*abs(EstPosDem-VoterIdeal).^UtilFuncParam+Gamma.*abs(EstPosRepCounterFacExpChall-VoterIdeal).^UtilFuncParam;

SingleIndexPolicyCounterFacDemInExpChall = -Gamma.*abs(EstPosDemCounterFacInExpChall-VoterIdeal).^UtilFuncParam+Gamma.*abs(EstPosRep_Polarization-VoterIdeal).^UtilFuncParam;
SingleIndexPolicyCounterFacRepInExpChall = -Gamma.*abs(EstPosDem_Polarization-VoterIdeal).^UtilFuncParam+Gamma.*abs(EstPosRepCounterFacInExpChall-VoterIdeal).^UtilFuncParam;

SingleIndexPolicyCounterFacDemInc_Polarization = -Gamma.*abs(EstPosDemCounterFacInc_Polarization-VoterIdeal).^UtilFuncParam+Gamma.*abs(EstPosRep-VoterIdeal).^UtilFuncParam;
SingleIndexPolicyCounterFacRepInc_Polarization = -Gamma.*abs(EstPosDem-VoterIdeal).^UtilFuncParam+Gamma.*abs(EstPosRepCounterFacInc_Polarization-VoterIdeal).^UtilFuncParam;

SingleIndexPolicyCounterFacDemExpChall_Polarization = -Gamma.*abs(EstPosDemCounterFacExpChall_Polarization-VoterIdeal).^UtilFuncParam+Gamma.*abs(EstPosRep-VoterIdeal).^UtilFuncParam;
SingleIndexPolicyCounterFacRepExpChall_Polarization = -Gamma.*abs(EstPosDem-VoterIdeal).^UtilFuncParam+Gamma.*abs(EstPosRepCounterFacExpChall_Polarization-VoterIdeal).^UtilFuncParam;

SingleIndexPolicyCounterFacDemInExpChall_Polarization = -Gamma.*abs(EstPosDemCounterFacInExpChall_Polarization-VoterIdeal).^UtilFuncParam+Gamma.*abs(EstPosRep-VoterIdeal).^UtilFuncParam;
SingleIndexPolicyCounterFacRepInExpChall_Polarization = -Gamma.*abs(EstPosDem-VoterIdeal).^UtilFuncParam+Gamma.*abs(EstPosRepCounterFacInExpChall_Polarization-VoterIdeal).^UtilFuncParam;

SingleIndexCounterFacDemInc = SingleIndexPolicyCounterFacDemInc + SingleIndexValCounterFacIncDem;
SingleIndexCounterFacRepInc = SingleIndexPolicyCounterFacRepInc + SingleIndexValCounterFacIncRep;

SingleIndexCounterFacDemExpChall = SingleIndexPolicyCounterFacDemExpChall + SingleIndexValCounterFacExpChallDem;
SingleIndexCounterFacRepExpChall = SingleIndexPolicyCounterFacRepExpChall + SingleIndexValCounterFacExpChallRep;

SingleIndexCounterFacDemInExpChall = SingleIndexPolicyCounterFacDemInExpChall + SingleIndexValCounterFacInExpChallDem;
SingleIndexCounterFacRepInExpChall = SingleIndexPolicyCounterFacRepInExpChall + SingleIndexValCounterFacInExpChallRep;


SingleIndexCounterFacDemInc_Polarization = SingleIndexPolicyCounterFacDemInc_Polarization + SingleIndexValCounterFacIncDem;
SingleIndexCounterFacRepInc_Polarization = SingleIndexPolicyCounterFacRepInc_Polarization + SingleIndexValCounterFacIncRep;

SingleIndexCounterFacDemExpChall_Polarization = SingleIndexPolicyCounterFacDemExpChall_Polarization + SingleIndexValCounterFacExpChallDem;
SingleIndexCounterFacRepExpChall_Polarization = SingleIndexPolicyCounterFacRepExpChall_Polarization + SingleIndexValCounterFacExpChallRep;

SingleIndexCounterFacDemInExpChall_Polarization = SingleIndexPolicyCounterFacDemInExpChall_Polarization + SingleIndexValCounterFacInExpChallDem;
SingleIndexCounterFacRepInExpChall_Polarization = SingleIndexPolicyCounterFacRepInExpChall_Polarization + SingleIndexValCounterFacInExpChallRep;


SingleIndexCounterFacDemInc_NoDir = SingleIndexPolicyCounterFacDemInc + SingleIndexVal;
SingleIndexCounterFacRepInc_NoDir = SingleIndexPolicyCounterFacRepInc + SingleIndexVal;

SingleIndexCounterFacDemExpChall_NoDir = SingleIndexPolicyCounterFacDemExpChall + SingleIndexVal;
SingleIndexCounterFacRepExpChall_NoDir = SingleIndexPolicyCounterFacRepExpChall + SingleIndexVal;

SingleIndexCounterFacDemInExpChall_NoDir = SingleIndexPolicyCounterFacDemExpChall + SingleIndexVal;
SingleIndexCounterFacRepInExpChall_NoDir = SingleIndexPolicyCounterFacRepExpChall + SingleIndexVal;

if ChoiceProbForm == 1

    PrVoteLeft = normcdf(SingleIndex, 0, 1);
    
    PrVoteLeft_Polarization = normcdf(SingleIndex_Polarization, 0, 1);
    
    PrVoteLeftCounterFacDemInc = normcdf(SingleIndexCounterFacDemInc, 0, 1);
    PrVoteLeftCounterFacRepInc = normcdf(SingleIndexCounterFacRepInc, 0, 1);
    
    PrVoteLeftCounterFacDemInc_Polarization = normcdf(SingleIndexCounterFacDemInc_Polarization, 0, 1);
    PrVoteLeftCounterFacRepInc_Polarization = normcdf(SingleIndexCounterFacRepInc_Polarization, 0, 1);
    
    PrVoteLeftCounterFacDemInc_NoDir = normcdf(SingleIndexCounterFacDemInc_NoDir, 0, 1);
    PrVoteLeftCounterFacRepInc_NoDir = normcdf(SingleIndexCounterFacRepInc_NoDir, 0, 1);

    PrVoteLeftCounterFacDemExpChall = normcdf(SingleIndexCounterFacDemExpChall, 0, 1);
    PrVoteLeftCounterFacRepExpChall = normcdf(SingleIndexCounterFacRepExpChall, 0, 1);
    
    PrVoteLeftCounterFacDemExpChall_Polarization = normcdf(SingleIndexCounterFacDemExpChall_Polarization, 0, 1);
    PrVoteLeftCounterFacRepExpChall_Polarization = normcdf(SingleIndexCounterFacRepExpChall_Polarization, 0, 1);
    
    PrVoteLeftCounterFacDemExpChall_NoDir = normcdf(SingleIndexCounterFacDemExpChall_NoDir, 0, 1);
    PrVoteLeftCounterFacRepExpChall_NoDir = normcdf(SingleIndexCounterFacRepExpChall_NoDir, 0, 1);

    PrVoteLeftCounterFacDemInExpChall = normcdf(SingleIndexCounterFacDemInExpChall, 0, 1);
    PrVoteLeftCounterFacRepInExpChall = normcdf(SingleIndexCounterFacRepInExpChall, 0, 1);
 
    PrVoteLeftCounterFacDemInExpChall_Polarization = normcdf(SingleIndexCounterFacDemInExpChall_Polarization, 0, 1);
    PrVoteLeftCounterFacRepInExpChall_Polarization = normcdf(SingleIndexCounterFacRepInExpChall_Polarization, 0, 1);
        
    PrVoteLeftCounterFacDemInExpChall_NoDir = normcdf(SingleIndexCounterFacDemInExpChall_NoDir, 0, 1);
    PrVoteLeftCounterFacRepInExpChall_NoDir = normcdf(SingleIndexCounterFacRepInExpChall_NoDir, 0, 1);

elseif ChoiceProbForm == 2
    
    PrVoteLeft = exp(SingleIndex)./(1+exp(SingleIndex)); 
    
    PrVoteLeft_Polarization = exp(SingleIndex_Polarization)./(1+exp(SingleIndex_Polarization)); 

    PrVoteLeftCounterFacDemInc = exp(SingleIndexCounterFacDemInc)./(1+exp(SingleIndexCounterFacDemInc));
    PrVoteLeftCounterFacRepInc = exp(SingleIndexCounterFacRepInc)./(1+exp(SingleIndexCounterFacRepInc));
  
    PrVoteLeftCounterFacDemInc_Polarization = exp(SingleIndexCounterFacDemInc_Polarization)./(1+exp(SingleIndexCounterFacDemInc_Polarization));
    PrVoteLeftCounterFacRepInc_Polarization = exp(SingleIndexCounterFacRepInc_Polarization)./(1+exp(SingleIndexCounterFacRepInc_Polarization));

    PrVoteLeftCounterFacDemInc_NoDir = exp(SingleIndexCounterFacDemInc_NoDir)./(1+exp(SingleIndexCounterFacDemInc_NoDir));
    PrVoteLeftCounterFacRepInc_NoDir = exp(SingleIndexCounterFacRepInc_NoDir)./(1+exp(SingleIndexCounterFacRepInc_NoDir)); 

    PrVoteLeftCounterFacDemExpChall = exp(SingleIndexCounterFacDemExpChall)./(1+exp(SingleIndexCounterFacDemExpChall));
    PrVoteLeftCounterFacRepExpChall = exp(SingleIndexCounterFacRepExpChall)./(1+exp(SingleIndexCounterFacRepExpChall));

    PrVoteLeftCounterFacDemExpChall_Polarization = exp(SingleIndexCounterFacDemExpChall_Polarization)./(1+exp(SingleIndexCounterFacDemExpChall_Polarization));
    PrVoteLeftCounterFacRepExpChall_Polarization = exp(SingleIndexCounterFacRepExpChall_Polarization)./(1+exp(SingleIndexCounterFacRepExpChall_Polarization));
       
    PrVoteLeftCounterFacDemExpChall_NoDir = exp(SingleIndexCounterFacDemExpChall_NoDir)./(1+exp(SingleIndexCounterFacDemExpChall_NoDir));
    PrVoteLeftCounterFacRepExpChall_NoDir = exp(SingleIndexCounterFacRepExpChall_NoDir)./(1+exp(SingleIndexCounterFacRepExpChall_NoDir)); 

    
    PrVoteLeftCounterFacDemInExpChall = exp(SingleIndexCounterFacDemInExpChall)./(1+exp(SingleIndexCounterFacDemInExpChall));
    PrVoteLeftCounterFacRepInExpChall = exp(SingleIndexCounterFacRepInExpChall)./(1+exp(SingleIndexCounterFacRepInExpChall));

    PrVoteLeftCounterFacDemInExpChall_Polarization = exp(SingleIndexCounterFacDemInExpChall_Polarization)./(1+exp(SingleIndexCounterFacDemInExpChall_Polarization));
    PrVoteLeftCounterFacRepInExpChall_Polarization = exp(SingleIndexCounterFacRepInExpChall_Polarization)./(1+exp(SingleIndexCounterFacRepInExpChall_Polarization));

    
    PrVoteLeftCounterFacDemInExpChall_NoDir = exp(SingleIndexCounterFacDemInExpChall_NoDir)./(1+exp(SingleIndexCounterFacDemInExpChall_NoDir));
    PrVoteLeftCounterFacRepInExpChall_NoDir = exp(SingleIndexCounterFacRepInExpChall_NoDir)./(1+exp(SingleIndexCounterFacRepInExpChall_NoDir)); 


end


%Weighting by District

ExpChalltoIncDem_Weighted_Holder = zeros(max(Dist_Index), 1);
ExpChalltoIncRep_Weighted_Holder = zeros(max(Dist_Index), 1);

ExpChalltoIncDem_Weighted_Holder_Polarization = zeros(max(Dist_Index), 1);
ExpChalltoIncRep_Weighted_Holder_Polarization = zeros(max(Dist_Index), 1);


ExpChalltoIncDem_Sig_Weighted_Holder = zeros(max(Dist_Index), 1);
ExpChalltoIncRep_Sig_Weighted_Holder = zeros(max(Dist_Index), 1);

InExpChalltoIncDem_Weighted_Holder = zeros(max(Dist_Index), 1);
InExpChalltoIncRep_Weighted_Holder = zeros(max(Dist_Index), 1);

InExpChalltoIncDem_Weighted_Holder_Polarization = zeros(max(Dist_Index), 1);
InExpChalltoIncRep_Weighted_Holder_Polarization = zeros(max(Dist_Index), 1);


InExpChalltoIncDem_Sig_Weighted_Holder = zeros(max(Dist_Index), 1);
InExpChalltoIncRep_Sig_Weighted_Holder = zeros(max(Dist_Index), 1);

IncAdvExpChallDem_Weighted_Holder = zeros(max(Dist_Index), 1);
IncAdvExpChallRep_Weighted_Holder = zeros(max(Dist_Index), 1);

IncAdvExpChallDem_Weighted_Holder_Polarization = zeros(max(Dist_Index), 1);
IncAdvExpChallRep_Weighted_Holder_Polarization = zeros(max(Dist_Index), 1);

IncAdvExpChallDem_Sig_Weighted_Holder = zeros(max(Dist_Index), 1);
IncAdvExpChallRep_Sig_Weighted_Holder = zeros(max(Dist_Index), 1);

IncAdvInExpChallDem_Weighted_Holder = zeros(max(Dist_Index), 1);
IncAdvInExpChallRep_Weighted_Holder = zeros(max(Dist_Index), 1);

IncAdvInExpChallDem_Weighted_Holder_Polarization = zeros(max(Dist_Index), 1);
IncAdvInExpChallRep_Weighted_Holder_Polarization = zeros(max(Dist_Index), 1);

IncAdvInExpChallDem_Sig_Weighted_Holder = zeros(max(Dist_Index), 1);
IncAdvInExpChallRep_Sig_Weighted_Holder = zeros(max(Dist_Index), 1);

for d = 1:max(Dist_Index)
    
    ExpChalltoIncDem_Weighted_Holder(d,:) = sum(PrVoteLeftCounterFacDemInc(Dist_Index==d & CandTypeDem(:,2)==1,:) - PrVoteLeft(Dist_Index==d & CandTypeDem(:,2)==1,:))/sum(Dist_Index==d & CandTypeDem(:,2) == 1);
    ExpChalltoIncRep_Weighted_Holder(d,:) =  sum(-(PrVoteLeftCounterFacRepInc(Dist_Index==d & CandTypeRep(:,2)==1,:) - PrVoteLeft(Dist_Index==d & CandTypeRep(:,2)==1,:)))/sum(Dist_Index==d & CandTypeRep(:,2) == 1);

    ExpChalltoIncDem_Weighted_Holder_Polarization(d,:) = sum(PrVoteLeftCounterFacDemInc_Polarization(Dist_Index==d & CandTypeDem(:,2)==1,:) - PrVoteLeft_Polarization(Dist_Index==d & CandTypeDem(:,2)==1,:))/sum(Dist_Index==d & CandTypeDem(:,2) == 1);
    ExpChalltoIncRep_Weighted_Holder_Polarization(d,:) =  sum(-(PrVoteLeftCounterFacRepInc_Polarization(Dist_Index==d & CandTypeRep(:,2)==1,:) - PrVoteLeft_Polarization(Dist_Index==d & CandTypeRep(:,2)==1,:)))/sum(Dist_Index==d & CandTypeRep(:,2) == 1);
    
    ExpChalltoIncDem_Sig_Weighted_Holder(d,:) = sum(PrVoteLeftCounterFacDemInc_NoDir(Dist_Index==d & CandTypeDem(:,2)==1,:) - PrVoteLeft(Dist_Index==d & CandTypeDem(:,2)==1,:))/sum(Dist_Index==d & CandTypeDem(:,2) == 1);
    ExpChalltoIncRep_Sig_Weighted_Holder(d,:) = sum(-(PrVoteLeftCounterFacRepInc_NoDir(Dist_Index==d & CandTypeRep(:,2)==1,:) - PrVoteLeft(Dist_Index==d & CandTypeRep(:,2)==1,:)))/sum(Dist_Index==d & CandTypeRep(:,2) == 1);

    InExpChalltoIncDem_Weighted_Holder(d,:) = sum(PrVoteLeftCounterFacDemInc(Dist_Index==d & CandTypeDem(:,3)==1,:) - PrVoteLeft(Dist_Index==d & CandTypeDem(:,3)==1,:))/sum(Dist_Index==d & CandTypeDem(:,3) == 1);
    InExpChalltoIncRep_Weighted_Holder(d,:) = sum(-(PrVoteLeftCounterFacRepInc(Dist_Index==d & CandTypeRep(:,3)==1,:) - PrVoteLeft(Dist_Index==d & CandTypeRep(:,3)==1,:)))/sum(Dist_Index==d & CandTypeRep(:,3) == 1);
 
    InExpChalltoIncDem_Weighted_Holder_Polarization(d,:) = sum(PrVoteLeftCounterFacDemInc_Polarization(Dist_Index==d & CandTypeDem(:,3)==1,:) - PrVoteLeft_Polarization(Dist_Index==d & CandTypeDem(:,3)==1,:))/sum(Dist_Index==d & CandTypeDem(:,3) == 1);
    InExpChalltoIncRep_Weighted_Holder_Polarization(d,:) = sum(-(PrVoteLeftCounterFacRepInc_Polarization(Dist_Index==d & CandTypeRep(:,3)==1,:) - PrVoteLeft_Polarization(Dist_Index==d & CandTypeRep(:,3)==1,:)))/sum(Dist_Index==d & CandTypeRep(:,3) == 1);
        
    InExpChalltoIncDem_Sig_Weighted_Holder(d,:) = sum(PrVoteLeftCounterFacDemInc_NoDir(Dist_Index==d & CandTypeDem(:,3)==1,:) - PrVoteLeft(Dist_Index==d & CandTypeDem(:,3)==1,:))/sum(Dist_Index==d & CandTypeDem(:,3) == 1);
    InExpChalltoIncRep_Sig_Weighted_Holder(d,:) = sum(-(PrVoteLeftCounterFacRepInc_NoDir(Dist_Index==d & CandTypeRep(:,3)==1,:) - PrVoteLeft(Dist_Index==d & CandTypeRep(:,3)==1,:)))/sum(Dist_Index==d & CandTypeRep(:,3) == 1);
    
    IncAdvExpChallDem_Weighted_Holder(d,:) = sum(PrVoteLeft(Dist_Index==d & CandTypeDem(:,1) == 1,:)-PrVoteLeftCounterFacDemExpChall(Dist_Index==d & CandTypeDem(:,1) == 1,:))/sum(Dist_Index==d & CandTypeDem(:,1) == 1);
    IncAdvExpChallRep_Weighted_Holder(d,:) = sum(-(PrVoteLeft(Dist_Index==d & CandTypeRep(:,1) == 1,:)-PrVoteLeftCounterFacRepExpChall(Dist_Index==d & CandTypeRep(:,1) == 1,:)))/sum(Dist_Index==d & CandTypeRep(:,1) == 1);

    IncAdvExpChallDem_Weighted_Holder_Polarization(d,:) = sum(PrVoteLeft_Polarization(Dist_Index==d & CandTypeDem(:,1) == 1,:)-PrVoteLeftCounterFacDemExpChall_Polarization(Dist_Index==d & CandTypeDem(:,1) == 1,:))/sum(Dist_Index==d & CandTypeDem(:,1) == 1);
    IncAdvExpChallRep_Weighted_Holder_Polarization(d,:) = sum(-(PrVoteLeft_Polarization(Dist_Index==d & CandTypeRep(:,1) == 1,:)-PrVoteLeftCounterFacRepExpChall_Polarization(Dist_Index==d & CandTypeRep(:,1) == 1,:)))/sum(Dist_Index==d & CandTypeRep(:,1) == 1);
    
    
    IncAdvExpChallDem_Sig_Weighted_Holder(d,:) = sum(PrVoteLeft(Dist_Index==d & CandTypeDem(:,1)==1,:)-PrVoteLeftCounterFacDemExpChall_NoDir(Dist_Index==d & CandTypeDem(:,1)==1,:))/sum(Dist_Index==d & CandTypeDem(:,1) == 1);
    IncAdvExpChallRep_Sig_Weighted_Holder(d,:) = sum(-(PrVoteLeft(Dist_Index==d & CandTypeRep(:,1)==1,:)-PrVoteLeftCounterFacRepExpChall_NoDir(Dist_Index==d & CandTypeRep(:,1)==1,:)))/sum(Dist_Index==d & CandTypeRep(:,1) == 1);

    IncAdvInExpChallDem_Weighted_Holder(d,:) = sum(PrVoteLeft(Dist_Index==d & CandTypeDem(:,1)==1,:)-PrVoteLeftCounterFacDemInExpChall(Dist_Index==d & CandTypeDem(:,1)==1,:))/sum(Dist_Index==d & CandTypeDem(:,1) == 1);
    IncAdvInExpChallRep_Weighted_Holder(d,:) = sum(-(PrVoteLeft(Dist_Index==d & CandTypeRep(:,1) == 1,:)-PrVoteLeftCounterFacRepInExpChall(Dist_Index==d & CandTypeRep(:,1) == 1,:)))/sum(Dist_Index==d & CandTypeRep(:,1) == 1);

    IncAdvInExpChallDem_Weighted_Holder_Polarization(d,:) = sum(PrVoteLeft_Polarization(Dist_Index==d & CandTypeDem(:,1)==1,:)-PrVoteLeftCounterFacDemInExpChall_Polarization(Dist_Index==d & CandTypeDem(:,1)==1,:))/sum(Dist_Index==d & CandTypeDem(:,1) == 1);
    IncAdvInExpChallRep_Weighted_Holder_Polarization(d,:) = sum(-(PrVoteLeft_Polarization(Dist_Index==d & CandTypeRep(:,1) == 1,:)-PrVoteLeftCounterFacRepInExpChall_Polarization(Dist_Index==d & CandTypeRep(:,1) == 1,:)))/sum(Dist_Index==d & CandTypeRep(:,1) == 1);
    
    IncAdvInExpChallDem_Sig_Weighted_Holder(d,:) = sum(PrVoteLeft(Dist_Index==d & CandTypeDem(:,1)==1,:)-PrVoteLeftCounterFacDemInExpChall_NoDir(Dist_Index==d & CandTypeDem(:,1)==1,:))/sum(Dist_Index==d & CandTypeDem(:,1) == 1);
    IncAdvInExpChallRep_Sig_Weighted_Holder(d,:) = sum(-(PrVoteLeft(Dist_Index==d & CandTypeRep(:,1)==1,:)-PrVoteLeftCounterFacRepInExpChall_NoDir(Dist_Index==d & CandTypeRep(:,1)==1,:)))/sum(Dist_Index==d & CandTypeRep(:,1) == 1);

end

ExpChalltoIncDem_Weighted = mean(ExpChalltoIncDem_Weighted_Holder(isnan(ExpChalltoIncDem_Weighted_Holder) == 0));
ExpChalltoIncRep_Weighted = mean(ExpChalltoIncRep_Weighted_Holder(isnan(ExpChalltoIncRep_Weighted_Holder) == 0));

ExpChalltoIncDem_Weighted_Polarization = mean(ExpChalltoIncDem_Weighted_Holder_Polarization(isnan(ExpChalltoIncDem_Weighted_Holder_Polarization) == 0));
ExpChalltoIncRep_Weighted_Polarization = mean(ExpChalltoIncRep_Weighted_Holder_Polarization(isnan(ExpChalltoIncRep_Weighted_Holder_Polarization) == 0));

ExpChalltoIncDem_Sig_Weighted = mean(ExpChalltoIncDem_Sig_Weighted_Holder(isnan(ExpChalltoIncDem_Sig_Weighted_Holder) == 0));
ExpChalltoIncRep_Sig_Weighted = mean(ExpChalltoIncRep_Sig_Weighted_Holder(isnan(ExpChalltoIncRep_Sig_Weighted_Holder) == 0));

InExpChalltoIncDem_Weighted = mean(InExpChalltoIncDem_Weighted_Holder(isnan(InExpChalltoIncDem_Weighted_Holder) == 0));
InExpChalltoIncRep_Weighted = mean(InExpChalltoIncRep_Weighted_Holder(isnan(InExpChalltoIncRep_Weighted_Holder) == 0));

InExpChalltoIncDem_Weighted_Polarization = mean(InExpChalltoIncDem_Weighted_Holder_Polarization(isnan(InExpChalltoIncDem_Weighted_Holder_Polarization) == 0));
InExpChalltoIncRep_Weighted_Polarization = mean(InExpChalltoIncRep_Weighted_Holder_Polarization(isnan(InExpChalltoIncRep_Weighted_Holder_Polarization) == 0));


InExpChalltoIncDem_Sig_Weighted = mean(InExpChalltoIncDem_Sig_Weighted_Holder(isnan(InExpChalltoIncDem_Sig_Weighted_Holder) == 0));
InExpChalltoIncRep_Sig_Weighted = mean(InExpChalltoIncRep_Sig_Weighted_Holder(isnan(InExpChalltoIncRep_Sig_Weighted_Holder) == 0));

IncAdvExpChallDem_Weighted = mean(IncAdvExpChallDem_Weighted_Holder(isnan(IncAdvExpChallDem_Weighted_Holder) == 0));
IncAdvExpChallRep_Weighted = mean(IncAdvExpChallRep_Weighted_Holder(isnan(IncAdvExpChallRep_Weighted_Holder) == 0));


IncAdvExpChallDem_Weighted_Polarization = mean(IncAdvExpChallDem_Weighted_Holder_Polarization(isnan(IncAdvExpChallDem_Weighted_Holder_Polarization) == 0));
IncAdvExpChallRep_Weighted_Polarization = mean(IncAdvExpChallRep_Weighted_Holder_Polarization(isnan(IncAdvExpChallRep_Weighted_Holder_Polarization) == 0));

IncAdvExpChallDem_Sig_Weighted = mean(IncAdvExpChallDem_Sig_Weighted_Holder(isnan(IncAdvExpChallDem_Sig_Weighted_Holder) == 0));
IncAdvExpChallRep_Sig_Weighted = mean(IncAdvExpChallRep_Sig_Weighted_Holder(isnan(IncAdvExpChallRep_Sig_Weighted_Holder) == 0));

IncAdvInExpChallDem_Weighted = mean(IncAdvInExpChallDem_Weighted_Holder(isnan(IncAdvInExpChallDem_Weighted_Holder) == 0));
IncAdvInExpChallRep_Weighted = mean(IncAdvInExpChallRep_Weighted_Holder(isnan(IncAdvInExpChallRep_Weighted_Holder) == 0));


IncAdvInExpChallDem_Weighted_Polarization = mean(IncAdvInExpChallDem_Weighted_Holder_Polarization(isnan(IncAdvInExpChallDem_Weighted_Holder_Polarization) == 0));
IncAdvInExpChallRep_Weighted_Polarization = mean(IncAdvInExpChallRep_Weighted_Holder_Polarization(isnan(IncAdvInExpChallRep_Weighted_Holder_Polarization) == 0));

IncAdvInExpChallDem_Sig_Weighted = mean(IncAdvInExpChallDem_Sig_Weighted_Holder(isnan(IncAdvInExpChallDem_Sig_Weighted_Holder) == 0));
IncAdvInExpChallRep_Sig_Weighted = mean(IncAdvInExpChallRep_Sig_Weighted_Holder(isnan(IncAdvInExpChallRep_Sig_Weighted_Holder) == 0));

SigDecomp_ExpChalltoIncDem = ExpChalltoIncDem_Sig_Weighted/ExpChalltoIncDem_Weighted;
SigDecomp_ExpChalltoIncRep = ExpChalltoIncRep_Sig_Weighted/ExpChalltoIncRep_Weighted;

SigDecomp_InExpChalltoIncDem = InExpChalltoIncDem_Sig_Weighted/InExpChalltoIncDem_Weighted;
SigDecomp_InExpChalltoIncRep = InExpChalltoIncRep_Sig_Weighted/InExpChalltoIncRep_Weighted;

SigDecomp_IncAdvExpChallDem = IncAdvExpChallDem_Sig_Weighted/IncAdvExpChallDem_Weighted;
SigDecomp_IncAdvExpChallRep = IncAdvExpChallRep_Sig_Weighted/IncAdvExpChallRep_Weighted;

SigDecomp_IncAdvInExpChallDem = IncAdvInExpChallDem_Sig_Weighted/IncAdvInExpChallDem_Weighted;
SigDecomp_IncAdvInExpChallRep = IncAdvInExpChallRep_Sig_Weighted/IncAdvInExpChallRep_Weighted;




